#include "mainscene.h"
#include "ui_mainscene.h"
#include<QTimer>

MainScene::MainScene(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainScene)
{
    ui->setupUi(this);

    //主场景基本配置
    //设置标题
    this->setWindowTitle("翻金币场景");
    //设置大小
    this->setFixedSize(320,588);
    //设置图标
    this->setWindowIcon(QIcon(":/res/Coin0001.png"));;

    //单机开始中的退出，实现退出游戏
    connect(ui->actiontuichu,&QAction::triggered,[=](){
        this->close();
    });
    //创建出选择关卡的场景
    chooseScene = new ChooseLevelScene;


    //开始按钮
    MyPushButton * startBtn = new MyPushButton(":/res/MenuSceneStartButton.png");
    startBtn->move(this->width()*0.5-startBtn->width()*0.5,this->height()*0.7);
    startBtn->setParent(this);

    //监听选择关卡场景中选择按钮的自定义信号
    connect(chooseScene,&ChooseLevelScene::chooseSceneBack,[=](){
        //主场景show出来
        this->show();
    });

    connect(startBtn,&MyPushButton::clicked,[=](){
        startBtn->zoom1();
        startBtn->zoom2();

        //延时进入到选择关卡场景
        QTimer::singleShot(300, this,[=](){
            this->hide();//隐藏主场景
            chooseScene->show();
        });//显示选择关卡场景
    });


}

//利用绘图事件绘制背景
void MainScene::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    QPixmap pix(":/res/PlayLevelSceneBg.png");
    painter.drawPixmap(0,0,this->width(),this->height(),pix);

    //加载标题
    pix.load(":/res/Title.png");
    pix = pix.scaled(pix.width() * 0.5, pix.height() * 0.5);
    painter.drawPixmap(10,30,pix.width(),pix.height(),pix);

}

MainScene::~MainScene()
{
    delete ui;
}

